<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * join short summary.
 *
 * join description.
 *
 * @version 1.0
 * @author xianbin
 */
class join extends Menu_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->Model('Join_model');
        $this->load->Model('Menu_model');
        $this->load->library('ajaxMsgModel');
        $this->load->library('form_validation');
    }

    public function joininfo()
    {
        $menuid=$this->uri->segment(4);
        $data['menuid']=$menuid;
        $data['crumbs_items']=$this->get_crumbs_content_menu($menuid);
        $data['joinModel']=$this->Join_model->get_first_row_by_menuid($menuid);
        $this->load->view('admin/join/joininfo.html',$data);
    }

    public function edit_join()
    {
        $this->load->library('ajaxMsgModel');
        $joinModel=new $this->Join_model();

        $joinModel->title=$this->input->post('title');
        $joinModel->contents=$this->input->post('contents',false);
        $joinModel->menuid=$this->input->post('menuid');
        $joinModel->description=$this->input->post('description');
        $joinModel->keyword=$this->input->post('keyword');
        $parent_menu_model=$this->Menu_model->get_menu_by_id($joinModel->menuid);
        $back_url=site_url('admin/'.$parent_menu_model->menu_control.'/'.$parent_menu_model->menu_action.($parent_menu_model->page_type==1?'list':'info').'/'.$parent_menu_model->menuid);
        if($this->input->post('mark')=="1")//修改
        {
            $joinModel->join_us_id=$this->input->post('join_us_id');
            $res= $this->Join_model->update_join($joinModel);
            if($res>0)
            {
                $this->ajaxmsgmodel->Msg='修改成功';
                $this->ajaxmsgmodel->Statu='ok';
                $this->ajaxmsgmodel->BackUrl=$back_url;
            }
            else
            {
                $this->ajaxmsgmodel->Msg='修改失败';
                $this->ajaxmsgmodel->Statu='err';
            }
        }else{//添加
            $res= $this->Join_model->add_join($joinModel);
            if($res>0)
            {
                $this->ajaxmsgmodel->Msg='添加成功';
                $this->ajaxmsgmodel->Statu='ok';
                $this->ajaxmsgmodel->BackUrl=$back_url;
            }
            else
            {
                $this->ajaxmsgmodel->Msg='添加失败';
                $this->ajaxmsgmodel->Statu='err';
            }
        }
        echo(json_encode($this->ajaxmsgmodel));
    }

    public function del_join()
    {
        $this->load->library('ajaxMsgModel');
        $join_id=$this->uri->segment(4);
        $join_model=$this->Join_model->get_join_by_id($join_id);
        $parent_menu_model=$this->Menu_model->get_menu_by_id($join_model->menuid);
        $back_url=site_url('admin/'.$parent_menu_model->menu_control.'/'.$parent_menu_model->menu_action.($parent_menu_model->page_type==1?'list':'info').'/'.$parent_menu_model->menuid);
        $res=$this->Join_model->del_join($join_id);
        if($res>0)
        {
            $this->ajaxmsgmodel->Msg='删除成功';
            $this->ajaxmsgmodel->Statu='ok';
            $this->ajaxmsgmodel->BackUrl=$back_url;
        }
        else
        {
            $this->ajaxmsgmodel->Msg='删除失败';
            $this->ajaxmsgmodel->Statu='err';
        }
        echo(json_encode($this->ajaxmsgmodel));
    }

}